/**=========================================================
 * Directive: grid-pagination.js
 =========================================================*/

App.directive('gridPagination', [
    function() {
        'use strict';
        
        return {
            restrict: 'EA',
            replace: true,
            template: function($element,$attrs){
                var pinning = $attrs.pinning == undefined ? '' : ' ui-grid-pinning ',
                    tree = $attrs.tree == undefined ? '' : ' ui-grid-tree-view ',
                    edit = $attrs.edit == undefined ? '' : ' ui-grid-edit ';
                return '\
                    <div>\
                        <div ui-grid="' + $attrs.optionModel + '" ui-grid-resize-columns ui-grid-pagination ui-grid-auto-resize ui-grid-selection ' + pinning + tree + edit + 'class="grid table-uigrid" style="' + $attrs.style + '"></div>\
                    </div>\
                '
            },
            link: function($scope, $element, $attrs){
                $scope.$watch($attrs.optionModel + ".status", 
                    function (newVal, oldVal) {   
                        if (newVal == 'loading'){
                            $element.addClass('whirl standard');
                        }else{
                            $element.removeClass('whirl standard');
                        }
                    }
                );
            }
        }
    }
]);
